//
//  ConfirmOrderViewController.m
//  MeterMart
//
//  Created by ENERGY on 2018/9/21.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "ConfirmOrderViewController.h"
#import "IWTextView.h"
#import "LocationManageViewController.h"
#import "PayWayViewController.h"
#import "MallProductDetailViewController.h"
#import "CartViewController.h"
#import "WeChatLoginViewController.h"
@interface ConfirmOrderViewController ()
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)UIView * topWhiteView;//上部白色背景
@property (nonatomic, strong)UIView * middleWhiteView;//中部白色背景
@property (nonatomic, strong)UIView * bottomWhiteView;//中部白色背景
@property (nonatomic, strong)UILabel * nameLab;//用户名
@property (nonatomic, strong)UILabel * phoneNum;//电话号
@property (nonatomic, strong)UILabel * defaultLab;//默认
@property (nonatomic, strong)UILabel * locationLab;//地址
@property (nonatomic, strong)UIImageView * produceImg;//商品图片
@property (nonatomic, strong)UILabel * produceTitleLab;//商品名
@property (nonatomic, strong)UILabel * priceLab;//金额
@property (nonatomic, strong)UILabel * numLab;//数量
@property (nonatomic, strong)NSString * numString;//数量
@property (nonatomic, strong)IWTextView * leaveMSGTextView;//留言内容
@property (nonatomic, strong)UILabel * listPriceLab;//商品订单
@property (nonatomic, strong)NSString * listID;//订单ID
@property (nonatomic, strong)NSDictionary * addressModel;//地址模型
@property (nonatomic, strong)NSDictionary * goodsModel;//商品模型
@property (nonatomic, strong)NSString * totalMoney;//总金额
@property (nonatomic, strong)NSString * addressContentID;//地址ID
@property (nonatomic, strong)UIButton * submitBtn;//提交订单
@property (nonatomic, strong)UIViewController * lastVC;//
@property (nonatomic, strong)UILabel * specificationLab;//规格
@property (nonatomic, strong)NSString * prodeceTitle;//商品名称
@property (nonatomic, strong)NSString * prodeceDescribe;//商品描述
@property (nonatomic, strong)UILabel * firstListLab;//首单立减
@property (nonatomic, strong)NSString * phoneString;
@property (nonatomic, strong)NSString * tokenString;
@property (nonatomic, assign)int presentTimes;//是否为modal回来后出来的页面
@property (nonatomic, strong)UIButton * arrowCoverBtn;//地址选择
@property (nonatomic, strong)WeChatLoginViewController * loginVC;
@property (nonatomic, strong)UINavigationController* loginNavi;
- (void)ifLogin;
@end

@implementation ConfirmOrderViewController(networking)
//从商品详情进入页面的接口
- (void)makeSureOrderList{
    if ([self.addressID isEqualToString:@""] || self.addressID.length == 0 || self.addressID == nil) {
        self.addressID = @"0";
    }
    NSDictionary * dic = @{
                           @"goodsid":self.produceID,
                           @"phone":self.phoneString,
                           @"token":self.tokenString,
                           @"goodssum":self.produceNum,
                           @"addressid":self.addressID,
                           @"handlength":self.handlength
                           };
    [self showprogressHUD];
    [[AFAppDotNetAPIClient sharedClient] POST:@"orderiosApi/createOrder" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([[NSString stringWithFormat:@"%@", responseObject[@"sign"]] isEqualToString:@"1"]) {
            self.goodsModel = responseObject[@"list"][@"goodsInfo"];
            self.addressModel = responseObject[@"list"][@"addressInfo"];
            self.totalMoney = responseObject[@"list"][@"totalmoney"];
            self.listPriceLab.text = [NSString stringWithFormat:@"共 %@ 件，实付款￥%@", self.goodsModel[@"goodssum"], self.totalMoney];
            self.listPriceLab.textColor = getColor(mainRedColor);
            if ([responseObject[@"list"][@"isfirst"] isEqualToString:@"1"]) {
                self.firstListLab.hidden = NO;
            }else{
                self.firstListLab.hidden = YES;
            }
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self.listPriceLab.text];
            NSRange range1 = [[str string] rangeOfString:@"共"];
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:range1];
            NSRange range2 = [[str string] rangeOfString:@"件"];
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:range2];
            NSRange range3 = [[str string] rangeOfString:@"，实付款"];
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:range3];
            self.listPriceLab.attributedText = str;
        }else if ([[NSString stringWithFormat:@"%@", responseObject[@"sign"]] isEqualToString:@"400"]) {
            [UserModel sharedInstanced].mobile = nil;
            [UserModel sharedInstanced].token = nil;
            [self ifLogin];
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}
//从地址管理页返回
- (void)locationManagerBack{
    if ([self.addressID isEqualToString:@""] || self.addressID == nil || [self.addressID length] == 0) {
        self.addressID = @"0";
    }
    NSDictionary * dic = @{
                           @"addressid":self.addressID,
                           @"goodsid":self.produceID,
                           @"phone":self.phoneString,
                           @"token":self.tokenString,
                           @"ordernum":self.listID
                           };
    [self showprogressHUD];
    [[AFAppDotNetAPIClient sharedClient] POST:@"orderiosApi/addorderaddress" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([responseObject[@"sign"] isEqualToString:@"1"]) {
            self.addressModel = responseObject[@"list"][@"addressInfo"];
        }else if ([[NSString stringWithFormat:@"%@", responseObject[@"sign"]] isEqualToString:@"400"]) {
            [UserModel sharedInstanced].mobile = nil;
            [UserModel sharedInstanced].token = nil;
            [self ifLogin];
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}
//从结算页面进入
- (void)cartAccount{
    NSDictionary * dic = @{
                           @"addressid":@"0",
                           @"cartid":self.produceID,
                           @"phone":self.phoneString,
                           @"token":self.tokenString
                           };
    [self showprogressHUD];
    [[AFAppDotNetAPIClient sharedClient] POST:@"orderiosApi/shopbalance" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([[NSString stringWithFormat:@"%@", responseObject[@"sign"]] isEqualToString:@"1"]) {
            self.goodsModel = responseObject[@"list"][@"goodsInfo"];
            self.addressModel = responseObject[@"list"][@"addressInfo"];
            self.totalMoney = responseObject[@"list"][@"totalmoney"];
            self.listPriceLab.text = [NSString stringWithFormat:@"共 %@ 件，实付款￥%@", self.goodsModel[@"goodssum"], self.totalMoney];
        }else if ([[NSString stringWithFormat:@"%@", responseObject[@"sign"]] isEqualToString:@"400"]) {
            [UserModel sharedInstanced].mobile = nil;
            [UserModel sharedInstanced].token = nil;
            [self ifLogin];
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}
@end
@implementation ConfirmOrderViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStatusBarBackgroundColor:[UIColor clearColor]];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.loginVC = [[WeChatLoginViewController alloc] init];
    self.loginNavi = [[UINavigationController alloc] initWithRootViewController:self.loginVC];
    __weak typeof (self)weakSelf = self;
    self.loginVC.backHomePageBlock = ^{
        [weakSelf.loginVC dismissViewControllerAnimated:YES completion:nil];
        [weakSelf.tabBarController setSelectedIndex:0];
    };
    if ([[UserModel sharedInstanced].token isEqualToString:@""] || [UserModel sharedInstanced].token == nil || [[UserModel sharedInstanced].token length] == 0 || [[UserModel sharedInstanced].mobile isEqualToString:@""] || [UserModel sharedInstanced].mobile == nil || [[UserModel sharedInstanced].mobile length] == 0) {
        if (self.presentTimes == 0) {
            self.presentTimes ++;
            [self.navigationController presentViewController:self.loginNavi animated:YES completion:nil];
        }else{
            [self.loginVC.navigationController dismissViewControllerAnimated:YES completion:nil];
            [self.tabBarController setSelectedIndex:0];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }return;
    }else{
        self.tokenString = [UserModel sharedInstanced].token;
        self.phoneString = [UserModel sharedInstanced].mobile;
    }
    if ([self.fromWhcichController isEqualToString:@"MallProductDetailViewController"]) {
        [self makeSureOrderList];//从商品详情进入页面
    }else if([self.fromWhcichController isEqualToString:@"LocationManageViewController"]){
        [self locationManagerBack];//从地址管理返回页面
    }else if([self.fromWhcichController isEqualToString:@"CartViewController"]){
        [self cartAccount];//从购物车页面进
    }else{
        if ([[UserModel sharedInstanced].token isEqualToString:@""] || [UserModel sharedInstanced].token == nil || [[UserModel sharedInstanced].token length] == 0 || [[UserModel sharedInstanced].mobile isEqualToString:@""] || [UserModel sharedInstanced].mobile == nil || [[UserModel sharedInstanced].mobile length] == 0) {
            [self ifLogin];
        }
    }
    self.fromWhcichController = @"";
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = getColor(mainColor);
    self.navigationItem.title = @"确认订单";
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
    [self setUpBottomTabBarView];
}

#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVI_HEIGHT - BOTTOM_HEIGHT - 49/WIDTH_6_SCALE) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = getColor(mainColor);
        _tableView.tableHeaderView = self.headerView;
    }return _tableView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _headerView.backgroundColor = getColor(mainColor);
        [self setUpTopWhiteView];
        [self setUpMiddleWhiteView];
        [self setUpBottomWhiteView];
    }return _headerView;
}
- (void)setUpTopWhiteView{
    //白色背景
    self.topWhiteView = [[UIView alloc] init];
    self.topWhiteView.backgroundColor = getColor(@"ffffff");
    [_headerView addSubview:self.topWhiteView];
    //姓名
    self.nameLab = [[UILabel alloc] init];
    [self label:self.nameLab withFont:DEF_FontSize_15 withText:@"用户名" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.topWhiteView];
    //电话号
    self.phoneNum = [[UILabel alloc] init];
    [self label:self.phoneNum withFont:DEF_FontSize_15 withText:@"xxxxxxxxxxx" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.topWhiteView];
    //默认
    self.defaultLab = [[UILabel alloc] init];
    [self label:self.defaultLab withFont:DEF_FontSize_10 withText:@"默认" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentCenter withView:self.topWhiteView];
    self.defaultLab.layer.borderColor = [UIColor blackColor].CGColor;
    self.defaultLab.layer.borderWidth = 1;
    //箭头
    UIImageView * arrowImg = [[UIImageView alloc] init];
    arrowImg.image = [UIImage imageNamed:@"in"];
    [self.topWhiteView addSubview:arrowImg];
    UIButton * arrowCoverBtn = [[UIButton alloc] init];
    self.arrowCoverBtn = arrowCoverBtn;
    [arrowCoverBtn addTarget:self action:@selector(arrowCoverBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.topWhiteView addSubview:arrowCoverBtn];
    //位置图标
    UIImageView * locationImg = [[UIImageView alloc] init];
    locationImg.image = [UIImage imageNamed:@"location"];
    [self.topWhiteView addSubview:locationImg];
    //具体地址
    self.locationLab = [[UILabel alloc] init];
    self.locationLab.numberOfLines = 0;
    self.locationLab.lineBreakMode = 0;
    [self label:self.locationLab withFont:DEF_FontSize_12 withText:@"具体地址" withTextColor:getColor(textGrayColor) withTextAlignment:NSTextAlignmentLeft withView:self.topWhiteView];
    //彩色条
    UIImageView * colorBarView = [[UIImageView alloc] init];
    colorBarView.image = [UIImage imageNamed:@"colorBar"];
    [self.topWhiteView addSubview:colorBarView];
    //masonry
    __weak typeof (self)weakSelf = self;
    [self.topWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(weakSelf.headerView);
        make.height.mas_offset(89/WIDTH_6_SCALE);
    }];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.headerView.mas_left).mas_offset(20/WIDTH_6_SCALE);
        make.top.equalTo(weakSelf.headerView.mas_top).mas_offset(15/WIDTH_6_SCALE);
    }];
    [self.phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(weakSelf.nameLab);
        make.left.equalTo(weakSelf.nameLab.mas_right).mas_offset(12/WIDTH_6_SCALE);
    }];
    [self.defaultLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(weakSelf.phoneNum);
        make.width.mas_offset(30/WIDTH_6_SCALE);
        make.left.equalTo(weakSelf.phoneNum.mas_right).mas_offset(9/WIDTH_6_SCALE);
    }];
    [arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.defaultLab.mas_centerY);
        make.right.equalTo(weakSelf.headerView.mas_right).mas_offset(-15/WIDTH_6_SCALE);
        make.height.mas_offset(12/WIDTH_6_SCALE);
        make.width.mas_offset(8/WIDTH_6_SCALE);
    }];
    [arrowCoverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(weakSelf.topWhiteView);
    }];
    [locationImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLab.mas_left);
        make.top.equalTo(weakSelf.nameLab.mas_bottom).mas_offset(10/WIDTH_6_SCALE);
        make.width.mas_offset(8/WIDTH_6_SCALE);
        make.height.mas_offset(13/WIDTH_6_SCALE);
    }];
    [self.locationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(locationImg.mas_right).mas_offset(12/WIDTH_6_SCALE);
        make.top.equalTo(locationImg.mas_top);
        make.right.equalTo(weakSelf.headerView.mas_right).mas_offset(-40/WIDTH_6_SCALE);
        make.bottom.lessThanOrEqualTo(colorBarView.mas_top).mas_offset(-2/WIDTH_6_SCALE);
    }];
    [colorBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.topWhiteView);
        make.height.mas_offset(2/WIDTH_6_SCALE);
    }];
}
- (void)setUpMiddleWhiteView{
    //中部白色背景
    self.middleWhiteView = [[UIView alloc] init];
    self.middleWhiteView.backgroundColor = [UIColor whiteColor];
    [_headerView addSubview:self.middleWhiteView];
    //商品图片
    self.produceImg = [[UIImageView alloc] init];
    self.produceImg.image = [UIImage imageNamed:@"YimiPlaceHolder"];
    [self.middleWhiteView addSubview:self.produceImg];
    //商品名
    self.produceTitleLab = [[UILabel alloc] init];
    [self label:self.produceTitleLab withFont:DEF_FontSize_14 withText:@"商品名称" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.middleWhiteView];
    self.produceTitleLab.numberOfLines = 0;
    self.produceTitleLab.lineBreakMode = 0;
    //商品价格
    self.priceLab = [[UILabel alloc] init];
    [self label:self.priceLab withFont:DEF_FontSize_15 withText:[NSString stringWithFormat:@"￥%@", @"---"] withTextColor:getColor(mainRedColor) withTextAlignment:NSTextAlignmentLeft withView:self.middleWhiteView];
//    self.priceLab.backgroundColor = [UIColor orangeColor];
    //数量
    self.numLab = [[UILabel alloc] init];
    [self label:self.numLab withFont:DEF_FontSize_15 withText:[NSString stringWithFormat:@"X  %@", @"-"] withTextColor:getColor(textGrayColor) withTextAlignment:NSTextAlignmentRight withView:self.middleWhiteView];
//    self.numLab.backgroundColor = [UIColor orangeColor];
    //规格
    self.specificationLab = [[UILabel alloc] init];
    [self label:self.specificationLab withFont:DEF_FontSize_15 withText:@"" withTextColor:getColor(textGrayColor) withTextAlignment:NSTextAlignmentCenter withView:self.middleWhiteView];
    //masonry
    __weak typeof (self)weakSelf = self;
    [self.middleWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.headerView);
        make.top.equalTo(weakSelf.topWhiteView.mas_bottom).mas_offset(10/WIDTH_6_SCALE);
        make.height.mas_offset(150/WIDTH_6_SCALE);
    }];
    [self.produceImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.middleWhiteView.mas_left).mas_offset(25/WIDTH_6_SCALE);
        make.top.equalTo(weakSelf.middleWhiteView.mas_top).mas_offset(23/WIDTH_6_SCALE);
        make.width.height.mas_offset(111/WIDTH_6_SCALE);
    }];
    [self.produceTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.produceImg.mas_right).mas_offset(30/WIDTH_6_SCALE);
        make.top.equalTo(weakSelf.middleWhiteView.mas_top).mas_offset(26/WIDTH_6_SCALE);
        make.right.equalTo(weakSelf.middleWhiteView.mas_right).mas_offset(-16/WIDTH_6_SCALE);
        make.bottom.lessThanOrEqualTo(weakSelf.priceLab.mas_top).mas_offset(-10/WIDTH_6_SCALE);
    }];
    [self.specificationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(weakSelf.priceLab);
        make.left.equalTo(weakSelf.priceLab.mas_right).priorityHigh();
        make.right.equalTo(self.numLab.mas_left);//must be low priority
    }];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.produceTitleLab.mas_left);
        make.bottom.equalTo(weakSelf.middleWhiteView.mas_bottom).mas_offset(-32/WIDTH_6_SCALE);
    }];
    [self.priceLab setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];//宽度不够时，可以被压缩
    [self.priceLab setContentHuggingPriority:UILayoutPriorityRequired/*抱紧*/
                                forAxis:UILayoutConstraintAxisHorizontal];
    [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.middleWhiteView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
        make.top.bottom.equalTo(weakSelf.priceLab);
    }];
    [self.numLab setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];//宽度不够时，可以被压缩
    [self.numLab setContentHuggingPriority:UILayoutPriorityRequired/*抱紧*/
                                     forAxis:UILayoutConstraintAxisHorizontal];
}
- (void)setUpBottomWhiteView{
    //底部白色背景
    self.bottomWhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 259/WIDTH_6_SCALE, SCREEN_WIDTH, 150/WIDTH_6_SCALE)];
    self.bottomWhiteView.backgroundColor = [UIColor whiteColor];
    [_headerView addSubview:self.bottomWhiteView];
    //留言
    UILabel * leaveMSGLab = [[UILabel alloc] initWithFrame:CGRectMake(22/WIDTH_6_SCALE, 27/WIDTH_6_SCALE, 40/WIDTH_6_SCALE, 15/WIDTH_6_SCALE)];
    [self label:leaveMSGLab withFont:DEF_FontSize_14 withText:@"留言:" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.bottomWhiteView];
    //留言输入
    self.leaveMSGTextView = [[IWTextView alloc] initWithFrame:CGRectMake(leaveMSGLab.right + 5/WIDTH_6_SCALE, leaveMSGLab.top - 9/WIDTH_6_SCALE, SCREEN_WIDTH - leaveMSGLab.right - 5/WIDTH_6_SCALE - leaveMSGLab.left, 150/WIDTH_6_SCALE - 54/WIDTH_6_SCALE)];
    self.leaveMSGTextView.placeholder = @"备注";
    self.leaveMSGTextView.font = DEF_FontSize_14;
    [self.bottomWhiteView addSubview:self.leaveMSGTextView];
    //首单提示
    self.firstListLab = [[UILabel alloc] initWithFrame:CGRectMake(leaveMSGLab.left, self.bottomWhiteView.bottom + 5/WIDTH_6_SCALE, SCREEN_WIDTH - 2* leaveMSGLab.left, 15/WIDTH_6_SCALE)];
    [self label:self.firstListLab withFont:DEF_FontSize_10 withText:@"*首单立减50元" withTextColor:getColor(mainRedColor) withTextAlignment:NSTextAlignmentLeft withView:_headerView];
    self.firstListLab.hidden = YES;
    _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.firstListLab.bottom + 20/WIDTH_6_SCALE);
}
- (void)setUpBottomTabBarView{
    UIView * bottomBar = [[UIView alloc] init];
    bottomBar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomBar];
    //总价
    self.listPriceLab = [[UILabel alloc] init];
    [self label:self.listPriceLab withFont:DEF_FontSize_14 withText:[NSString stringWithFormat:@"共 - 件，实付款￥---"] withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentRight withView:bottomBar];
    //提交订单
    UIButton * submitBtn = [[UIButton alloc] init];
    submitBtn.titleLabel.font = DEF_FontSize_15;
    [submitBtn setTitle:@"提交订单" forState:UIControlStateNormal];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [submitBtn setBackgroundColor:getColor(@"e92600")];
    [submitBtn addTarget:self action:@selector(submitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.submitBtn = submitBtn;
    [bottomBar addSubview:submitBtn];
    //masonry
    __weak typeof (self)weakSelf = self;
    [bottomBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.bottom.equalTo(weakSelf.view.mas_bottom).mas_offset(-BOTTOM_HEIGHT);
        make.height.mas_offset(49/WIDTH_6_SCALE);
    }];
    [self.listPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(submitBtn.mas_left).mas_offset(-3/WIDTH_6_SCALE);
        make.top.bottom.equalTo(bottomBar);
    }];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(bottomBar);
        make.width.mas_offset(107/WIDTH_6_SCALE);
    }];
}
- (void)setAddressModel:(NSDictionary *)addressModel{
    _addressModel = addressModel;
    if (addressModel.count > 1) {
        self.locationLab.text = [NSString stringWithFormat:@"%@%@%@%@", addressModel[@"receiveprovince"], addressModel[@"receivecity"], addressModel[@"receivearea"], addressModel[@"receiveaddress"]];
        if ([addressModel[@"status"] isEqualToString:@"1"]) {
            self.defaultLab.hidden = NO;
        }else{
            self.defaultLab.hidden = YES;
        }
        self.nameLab.text = addressModel[@"receivename"];
        self.phoneNum.text = addressModel[@"receivephone"];
        self.addressContentID = addressModel[@"addressid"];
        self.locationLab.textColor = getColor(textGrayColor);
        self.submitBtn.userInteractionEnabled = YES;
        [self.submitBtn setTitle:@"提交订单" forState:UIControlStateNormal];
        [self.submitBtn setBackgroundColor:getColor(@"e92600")];
    }else{
        self.nameLab.text = @"用户名";
        self.phoneNum.text = @"xxxxxxxxxxx";
        self.submitBtn.userInteractionEnabled = NO;
        [self.submitBtn setBackgroundColor:[UIColor grayColor]];
        self.locationLab.text = @"请填写具体地址";
        self.locationLab.textColor = [UIColor redColor];
    }
}
- (void)setGoodsModel:(NSDictionary *)goodsModel{
    _goodsModel = goodsModel;
    self.produceTitleLab.text = [NSString stringWithFormat:@"%@  %@", goodsModel[@"goodsname"], goodsModel[@"goodsdescribe"]];
    self.prodeceDescribe = goodsModel[@"goodsdescribe"];
    self.prodeceTitle = goodsModel[@"goodsname"];
    [self.produceImg sd_setImageWithURL:[NSURL URLWithString:goodsModel[@"goodsimg"]] placeholderImage:[UIImage imageNamed:@"YimiPlaceHolder"]];
    self.numLab.text = [NSString stringWithFormat:@"X   %@", goodsModel[@"goodssum"]];
    self.numString = goodsModel[@"goodssum"];
    self.priceLab.text = [NSString stringWithFormat:@"￥%@", goodsModel[@"groupprice"]];
    self.listID = goodsModel[@"ordernum"];
    if ([goodsModel[@"handlength"] isEqualToString:@"0"] || [goodsModel[@"handlength"] length] == 0 || [goodsModel[@"handlength"] isEqualToString:@""] || goodsModel[@"handlength"] == nil) {
        self.specificationLab.text = @"";
    }else{
        self.specificationLab.text = goodsModel[@"handlength"];
    }
}
#pragma mark - action
- (void)arrowCoverBtnClick:(UIButton *)sender{
    NSLog(@"箭头");
    __weak typeof (self)weakSelf = self;
    LocationManageViewController * vc = [[LocationManageViewController alloc] init];
    vc.takeAddressIDBlock = ^(NSString *addressID, NSString * controllerName) {
        weakSelf.addressID = addressID;
        weakSelf.fromWhcichController = controllerName;
//        [weakSelf locationManagerBack];
    };
    vc.addressContentID = self.addressContentID;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)submitBtnClick:(UIButton *)sender{
    PayWayViewController * vc = [[PayWayViewController alloc] init];
    vc.listID = self.goodsModel[@"ordernum"];
    vc.remarks = self.leaveMSGTextView.text;
    vc.produceTitle = self.prodeceTitle;
    vc.produceDescribe = self.prodeceDescribe;
    if ([self.leaveMSGTextView.text isEqualToString:@""] || self.leaveMSGTextView.text == nil || self.leaveMSGTextView.text.length == 0) {
        vc.remarks = @"";
    }
    vc.numString = self.numString;
    vc.addressID = self.addressContentID;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)ifLogin{
    [self presentViewController:self.loginNavi animated:YES completion:nil];
}
@end
